<template>
  <div class="app-container">
    <el-table :data="penpelList" border style="width: 100%;" >
      <el-table-column prop="id" label="ID" >
      </el-table-column>
      <el-table-column prop="name" label="姓名" >
    </el-table-column>
      <el-table-column prop="heart_answer" label="心理问题答案">
      </el-table-column>
      <el-table-column prop="law_answer" label="法律问题答案">
      </el-table-column>
      <el-table-column prop="sign_date" label="报名时间" >
    </el-table-column>
      <el-table-column prop="status" label="状态">
      </el-table-column>
      <el-table-column align="center" label="操作" width="260" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="small" type="success" @click="updatePenpel(scope.row, '审核通过')">同意</el-button>
          <el-button size="small" type="danger" @click="updatePenpel(scope.row, '审核失败')">拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import { fetchPenpelList, deletePenpelById, updatePenpelById } from '@/api/activity'
  import waves from '@/directive/waves'
  export default {
    directives: {
      waves
    },
    data() {
      return {
        penpelList: null,
        total: null,
        xx: null,
        listQuery: {
          page: 1,
          size: 10,
          uid: undefined
        }
      }
    },
    created() {
      this.getPenpelList()
    },
    methods: {
      getPenpelList() {
        fetchPenpelList(this.listQuery).then(response => {
          this.penpelList = response.data.rows
          this.total = response.data.total
        })
      },
      deletePenpel(id) {
        deletePenpelById(id)
        this.$message({
          message: '操作成功',
          type: 'success'
        })
      },
      updatePenpel(penpel, num) {
        this.xx = penpel
        this.xx.status = num
        updatePenpelById(this.xx)
        this.$message({
          message: '操作成功',
          type: 'success'
        })
      },
      handleFilter() {
        this.listQuery.page = 1
        this.getPenpelList()
      },
      handleSizeChange(val) {
        this.listQuery.size = val
        this.getPenpelList()
      },
      handleCurrentChange(val) {
        this.listQuery.page = val
        this.getPenpelList()
      }
    }
  }
</script>

<style scoped>
  .app-container{
    padding: 30px;
  }
</style>
